<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'qun';
model('jy_scrm/member')->checklogin();
$return['pluginset']['title']=$return['pluginset']['title']?:'企业微信';
$id=intval($_RQ['id']);
if($_RQ['op']=='qun'){
	set_html('title','加入企业微信群');
	$item=pdo_get('jy_scrm_qun',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['sharedata']=array(
			'title'=>'加入《'.$item['title'].'》-'.$return['pluginset']['title'],
			'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'企业微信SCRM，用心链接客户！',
			'link'=>custom_url('jy_merchscrm/gochat/'.$_RQ['op'].'/id='.$id,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	$addlog=pdo_get('jy_scrm_qun_addlog',array('merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
	if(!$addlog['id'] && $_RQ['fromqun']){
		$data=array(
			'uniacid'=>$_SESSION['uniacid'],
			'merchid'=>$_SESSION['onemerchid'],
			'mid'=>$_SESSION['uid'],
			'qun_id'=>$id,
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_scrm_qun_addlog',$data);
	}
	$return['item']=$item;
	if($addlog['id']){
		$return['errormsg']='您已加过本群，无需再加，您可以分享本群给朋友们！';
		exi($return);
	}elseif($_SESSION['openid'] && !$_RQ['fromqun']){
		if(!$item['ewmurl']){
			$return['errormsg']='该群未添加《群加入二维码链接地址》';
			exi($return);
		}else{
			exi('','',$item['ewmurl']);
		}
	}else{
		$return['errormsg']='非微信环境下访问，不能直接加群，可以尝试扫码！';
		exi($return);
	}
}
if($_RQ['op']=='worker'){
	set_html('title','联系客服');
	$item=pdo_get('jy_scrm_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['sharedata']=array(
			'title'=>'联系客服《'.$item['name'].'》-'.$return['pluginset']['title'],
			'desc'=>$return['pluginset']['share_desc']?$return['pluginset']['share_desc']:'企业微信SCRM，用心链接客户！',
			'link'=>custom_url('jy_merchscrm/gochat/'.$_RQ['op'].'/id='.$id,true),
			'imgUrl'=>ATTACHMENT_URL.$return['pluginset']['share_image']
	);
	$return['item']=$item;
	if($_SESSION['openid']){
		if(!$item['ewmurl']){
			$return['errormsg']='该群未添加《联系客服二维码链接地址》';
			exi($return);
		}else{
			exi('','',$item['ewmurl']);
		}
	}else{
		$return['errormsg']='非微信环境下访问，不能直接联系客服，可以尝试扫码！';
		exi($return);
	}
}
?>